﻿using SharpKit.JavaScript;
using System;

namespace SharpKit.Onx
{
    /// <summary>
    /// Mode of Transport monitor. Encapsulates the detection of mode of transport. Currently MOT supports these states: 'atrest', 'walking', 'driving', and 'running'
    /// https://www.onx.ms/#apiPage/modeOfTransport
    /// </summary>
    [JsType(Mode = JsMode.Prototype, Export = false)]
    public class ModeOfTransport : Emitter
    {
        //No way to new this up
        private ModeOfTransport()
        { }

        #region Properties

        /// <summary>
        ///  Get the current mode of transport. Note: this value is updated only as long as there are listeners registered on 'changed' event.
        /// </summary>
        [JsProperty(Name = "current", NativeField = true)]
        public ModeOfTransportType Current { get { return ModeOfTransportType.AtRest; } }

        /// <summary>
        /// Get/set the current accelerometer sampling interval. The interval is measured in milliseconds.
        /// The minimal interval is used for all scripts that use Mode of Transport. 
        /// The interval should be bounded between 15 seconds and 1 hour.
        /// </summary>
        [JsProperty(Name = "samplingInterval", NativeField = true)]
        public long SamplingInterval { get; set; }

        #endregion


        #region Triggers (Events)
        /// <summary>
        /// trigger is received when a change in mode of transport is detected. Additional trigger data is available in the MOTSignal parameter passed to the callback function.
        /// </summary>
        public event Action<MOTSignal> Changed
        {
            [JsMethod(Name = "on", InsertArg0 = "'changed'")]
            add
            {
            }
            [JsMethod(Name = "removeListener", InsertArg0 = "'changed'")]
            remove
            {
            }
        }
        #endregion
    }

    /// <summary>
    /// Currently MOT supports these states: 'atrest', 'walking', 'driving', and 'running'
    /// </summary>
    [JsType(Mode = JsMode.Json, Export = false)]
    [JsEnum(ValuesAsNames = true)]
    public enum ModeOfTransportType
    {
        /// <summary>
        /// At rest
        /// </summary>
        [JsField(Name = "atrest")]
        AtRest,

        /// <summary>
        /// Walking
        /// </summary>
        [JsField(Name = "walking")]
        Walking,

        /// <summary>
        /// Driving
        /// </summary>
        [JsField(Name = "driving")]
        Driving,

        /// <summary>
        /// Running
        /// </summary>
        [JsField(Name = "running")]
        Running
    };

    /// <summary>
    /// This class represents the current user's mode of transport. Currently MOT supports these states: 'atrest', 'walking', 'driving', and 'running'
    /// </summary>
    [JsType(Mode = JsMode.Json, Export = false)]
    public class MOTSignal : ScriptSignal
    {
        /// <summary>
        /// Retrieves the newly detected mode of transport state associated with this signal
        /// </summary>
        [JsProperty(NativeField = true, Name = "current")]
        public ModeOfTransportType Current { get; set; }

        /// <summary>
        /// Retrieves the newly detected mode of transport state associated with this signal
        /// </summary>
        [JsProperty(NativeField = true, Name = "previous")]
        public ModeOfTransportType Previous { get; set; }
    }
}